package jzqb.controller;

import haha.life.common.CutPageBean;
import haha.life.normal.FileuploadUtils;
import io.swagger.annotations.Api;
import jzqb.bo.ResultBo;
import jzqb.bo.StandardBo;
import jzqb.common.Result;
import jzqb.service.ResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.websocket.server.PathParam;

@RestController
@CrossOrigin
@RequestMapping("/result")
@Api(tags = "情报成果")
public class ResultController {


    @Autowired
    ResultService resultService;

    /**
     * 主页的结果集
     * @param resultBo
     * @return
     */
    @PostMapping("/complexSearch")
    public Result ComplexSearch(@RequestBody ResultBo resultBo) {
        CutPageBean<StandardBo> result = resultService.ComplexSearch(resultBo);
        return Result.succ(result);
    }

    /**
     * sysID 查询情报成果详情
     */
    @PostMapping("/getResultDetail")
    public Result getResultDetail(@RequestBody ResultBo resultBo) {
        Result result = resultService.getResultDetail(resultBo);
        return result;
    }

    @GetMapping("/getFileResult")
    public void getResultDetail(@PathParam("coverPage") String coverPage, HttpServletResponse response) {
        if ("".equals(coverPage) || coverPage == null) {
            return ;
        }
        try {
            FileuploadUtils.download(coverPage, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
